//
//  BaseLoginViewController.m
//  WeChat
//
//  Created by wpapple on 16/6/15.
//  Copyright © 2016年 红红火火恍恍惚惚嘿嘿嘿. All rights reserved.
//

#import "BaseLoginViewController.h"
#import "AppDelegate.h"
#import "WPXMPPTools.h"

@implementation BaseLoginViewController

-(void)login:(NSString *)userName andPassword:(NSString *)password{
    
    WPUserInfo * wpUserInfo = [WPUserInfo sharedWPUserInfo];
    
    wpUserInfo.user = userName;
    wpUserInfo.pwd = password;
    
//    AppDelegate * app = [UIApplication sharedApplication].delegate;
    
    __weak typeof(self) w_self = self;
    [[WPXMPPTools sharedWPXMPPTools] xmppLogin:^(XMPPState state) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [w_self dealXMPPSate:state];
        });
    }];
    
}

-(void)dealXMPPSate:(XMPPState)state{
    switch (state) {
        case XMPPLoginSuccess:
        {
            NSLog(@"登录成功");
            
            //            UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            //            self.view.window.rootViewController = storyboard.instantiateInitialViewController;
            
        }
            
            break;
            
        case XMPPLoginFailure:{
            NSLog(@"登录失败");
            [MBProgressHUD showError:@"账号或者密码错误" toView:self.view];
        }
            
        default:
            break;
    }
}

@end
